package com.zigong.app.ui.utils;

import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.ijkplaylib.widget.GPlayerView;
import com.ruihang.ijkplaylib.widget.IjkVideoView;
import com.zigong.app.R;
import com.zigong.app.beans.LiveInfo;

import java.util.Arrays;

/**
 * Created by liuyu on 2017/8/3.
 */

public class LivingBottomControllerImp extends AbsLivingBottomController {

    private CustomFontTextView topTitle;

    private boolean hasBarrageAction;

    public LivingBottomControllerImp(AppCompatActivity activity) {
        super(activity);
    }

    @Override
    public boolean canChangeScreen() {
        return true;
    }

    @Override
    public void onUpdateUI(boolean isPlaying, boolean isLive, boolean isPortrait) {
        if (isPlaying) {
            if (isLive) {
                playBtn.setImageResource(R.mipmap.icon_living_cr_pause_white);
            } else {
                playBtn.setImageResource(R.mipmap.icon_living_cr_pause_white);
            }
        } else {
            playBtn.setImageResource(R.mipmap.icon_living_cr_play_white);
        }
    }

    @Override
    public void setHasBarrage(boolean hasBarrage) {
        boolean b = this.hasBarrageAction != hasBarrage;
        this.hasBarrageAction = hasBarrage;
        if (b && barrageBtn != null) {
            barrageBtn.setVisibility(hasBarrage ? View.VISIBLE : View.GONE);
        }
    }

    @NonNull
    @Override
    public View onCreateView(GPlayerView playerView, LayoutInflater inflater, ViewGroup group) {
        View v = inflater.inflate(R.layout.living_play_bottom_controll, group, false);
        topTitle = (CustomFontTextView) v.findViewById(R.id.living_top_title);
        playBtn = (ImageView) v.findViewById(R.id.living_top_img_play);
        barrageBtn = (CustomFontTextView) v.findViewById(R.id.living_top_barrage);
        fullBtn = (CustomFontTextView) v.findViewById(R.id.living_top_full_screen);
        barrageBtn.setVisibility(hasBarrageAction ? View.VISIBLE : View.GONE);
        return v;
    }

    @CallSuper
    @Override
    public void onDestory() {
        super.onDestory();
        topTitle.setOnClickListener(null);
    }

    public void initInfo(LiveInfo info) {
        if (info == null) {
            return;
        }
        topTitle.setText(info.getLiveTitle());
    }

}
